﻿<%@ Control Language="C#" AutoEventWireup="false" EnableViewState="true" CodeBehind="Paging.ascx.cs" Inherits="CMS.Web.Site.Ascx.Paging" %>

<div id="uc_paging">
	<span class="count">
	第 <span id="pageIndex">1</span> 页 &nbsp;/&nbsp;
	共 <span id="pageCount"><%=PageCount %></span> 页&nbsp;&nbsp;&nbsp;
	共 <span id="recCount"><%=RecordCount %></span> 条
	</span>
	<a href="javascript:pager('<<')">首页</a>&nbsp;
	<a href="javascript:pager('<')">上一页</a>&nbsp;
	<a href="javascript:pager('>')">下一页</a>&nbsp;
	<a href="javascript:pager('>>')">尾页</a>&nbsp;&nbsp;&nbsp;
	<select class="selPage" onchange="pager(this.value)"></select>
</div>

<script type="text/javascript">
	
	$(function() {
		if ($("#" + "<%=ContainerID %>").html().length < 200) { // no data
			$('#uc_paging').hide();
			return;
		}
		
		var pageCount = $("#pageCount").text();
		var obj = $(".selPage");
		
		for (i = 1; i <= pageCount; i++) {
			obj.append("<option value='" + i + "'>第" + i + "页</option>");
		}
	});	
	
	function pager(tag) {
		var categoryId = "<%= CategoryID %>";
		var pageType = "<%= PageType %>";
		var pageSize = "<%= PageSize %>";
		var dom = $("#" + "<%=ContainerID %>");
		var pageIndex = 0;
		
		if (tag == ">")
			pageIndex = parseInt($('#pageIndex').text()) + 1;
		else if (tag == "<")
			pageIndex = parseInt($('#pageIndex').text()) - 1;
		else if (tag == "<<")
			pageIndex = 1;
		else if (tag == ">>")
			pageIndex = parseInt($('#pageCount').text());
		else
			pageIndex = parseInt(tag);
		
		if (pageIndex < 1 || pageIndex > parseInt($('#pageCount').text()))
			return;
			
		$('#pageIndex').text(pageIndex);
		$('.selPage').val(pageIndex);
		
		$.get(
			"../ashx/Paging.ashx",
			{ "categoryId":categoryId, "pageType":pageType, "pageSize":pageSize, "pageIndex":pageIndex },
			function(data) {
				dom.html(data);
			}
		);
	}
</script>